package com.qk.controller;

import com.qk.common.Result;
import com.qk.entity.User;
import com.qk.service.UserService;
import com.qk.vo.LoginResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class LoginResultController {
    private final UserService userService;

    public LoginResultController(UserService userService) {
        this.userService = userService;
    }

    @PostMapping("/login")
    public Result login(@RequestBody User user) {
      LoginResultVo loginResultVo = userService.login(user);
      if(loginResultVo == null){
          log.info("登录失败");
          return Result.error("登录失败");
      }
        log.info("登录成功");
        return Result.success(loginResultVo);
    }
}
